from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.base import TaskResult
from autogen_agentchat.conditions import TextMentionTermination, ExternalTermination, MaxMessageTermination, \
    TextMessageTermination
from autogen_agentchat.messages import TextMessage
from autogen_agentchat.teams import RoundRobinGroupChat
from autogen_agentchat.ui import Console
from autogen_core import CancellationToken
from autogen_core.memory import ListMemory, MemoryContent
from autogen_core.model_context import BufferedChatCompletionContext
from autogen_ext.models.openai import OpenAIChatCompletionClient

model_client = OpenAIChatCompletionClient(model="modelscope.cn/Qwen/Qwen2.5-7B-Instruct-GGUF:q5_k_m",
                                          model_info={
                                              "vision": False,
                                              "function_calling": True,
                                              "family": "Qwen3",
                                              "structured_output": True,
                                              "json_output": True,
                                              "multiple_system_messages": True,
                                          },
                                          api_key="ollama",
                                          base_url="http://127.0.0.1:11434/v1")


async def test_memory():
    memory = ListMemory()
    await memory.add(MemoryContent(content="用户喜欢披萨.", mime_type="text/plain"))
    await memory.add(MemoryContent(content="用户不喜欢奶酪.", mime_type="text/plain"))
    model_context = BufferedChatCompletionContext(buffer_size=10)
    await memory.update_context(model_context)
    print(await model_context.get_messages())
    agent = AssistantAgent(
        name="assistant",
        model_client=model_client,
        memory=[memory],
        system_message="你是一个帮助AI助手，擅长提供晚餐建议。",
    )

    result = await agent.run(task="有什么好的晚餐建议吗？")
    print(result.messages[-1].content)

if __name__ == "__main__":
    import asyncio
    asyncio.run(test_memory())